package io.gitee.tziye.core.kv.model;

import io.gitee.tziye.RenaiClient;
import io.gitee.tziye.core.kv.MapOperator;
import io.gitee.tziye.core.kv.RenaiKey;
import io.gitee.tziye.core.kv.RenaiValue;
import io.gitee.tziye.enums.KvType;

import java.util.Collection;
import java.util.List;
import java.util.Map;

public class RenaiMap<T> extends RenaiKVCollection<T> {

    private final MapOperator mapOperator;

    public RenaiMap(RenaiClient renaiClient, String key, Class<T> clazz, Integer expireSeconds) {
        super(renaiClient, key, clazz, KvType.Map);
        mapOperator = renaiClient.map();
        mapOperator.saveKey(key, expireSeconds);
    }

    @Override
    public RenaiKey key() {
        return mapOperator.key(key);
    }

    @Override
    public void expire(int expireSeconds) {
        mapOperator.expire(key, expireSeconds);
    }

    @Override
    public boolean exists() {
        return mapOperator.exists(key);
    }

    @Override
    public boolean delete() {
        return mapOperator.delete(key);
    }

    @Override
    public List<RenaiValue> values(String key) {
        return mapOperator.values(key);
    }

    @Override
    public int size() {
        return mapOperator.size(key);
    }

    @Override
    public boolean contains(T value) {
        return mapOperator.contains(key, value);
    }

    @Override
    public int clear() {
        return mapOperator.clear(key);
    }

    @Override
    public boolean remove(T value) {
        return mapOperator.remove(key, value);
    }

    @Override
    public int removeValues(List<T> values) {
        return mapOperator.removeValues(key, values);
    }

    public Map<String, T> members() {
        return mapOperator.members(key, clazz);
    }

    public void put(String subKey, T value) {
        mapOperator.put(key, subKey, value);
    }

    public void put(Map<String, T> map) {
        mapOperator.put(key, map);
    }

    public T get(String subKey) {
        return mapOperator.get(key, subKey, clazz);
    }

    public Map<String, T> get(Collection<String> subKeys) {
        return mapOperator.get(key, subKeys, clazz);
    }

    public T pop(String subKey) {
        return mapOperator.pop(key, subKey, clazz);
    }

    public Map<String, T> pop(Collection<String> subKeys) {
        return mapOperator.pop(key, subKeys, clazz);
    }

    public boolean containsKey(String subKey) {
        return mapOperator.containsKey(key, subKey);
    }

    public boolean removeKey(String subKey) {
        return mapOperator.removeKey(key, subKey);
    }

    public int removeKeys(List<String> subKeys) {
        return mapOperator.removeKeys(key, subKeys);
    }

    public long incr(String subKey, long num) {
        return mapOperator.incr(key, subKey, num);
    }

}
